<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Nginx,Tomcat," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="一、Hello world前期环境准备 准备两个解压版tomcat，如何同时启动两个tomcat，请看我的另一篇文章《一台机器同时启动多个tomcat》。  nginx官网下载解压版nginx。  创建一个简单的web项目。为了直观的区分访问的哪个tomcat，在页面写上标记8081、8082。     分别部署到对应的tomcat下。如图：    配置nginx&amp;#160;&amp;#160;&amp;#160">
<meta name="keywords" content="Nginx,Tomcat">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx + Tomcat 配置负载均衡集群">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/Tomcat/7. Nginx + Tomcat 配置负载均衡集群/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="一、Hello world前期环境准备 准备两个解压版tomcat，如何同时启动两个tomcat，请看我的另一篇文章《一台机器同时启动多个tomcat》。  nginx官网下载解压版nginx。  创建一个简单的web项目。为了直观的区分访问的哪个tomcat，在页面写上标记8081、8082。     分别部署到对应的tomcat下。如图：    配置nginx&amp;#160;&amp;#160;&amp;#160">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/01.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/02.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/03.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/04.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/05.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/06.png?raw=true">
<meta property="og:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/07.png?raw=true">
<meta property="og:updated_time" content="2017-09-02T17:37:04.816Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Nginx + Tomcat 配置负载均衡集群">
<meta name="twitter:description" content="一、Hello world前期环境准备 准备两个解压版tomcat，如何同时启动两个tomcat，请看我的另一篇文章《一台机器同时启动多个tomcat》。  nginx官网下载解压版nginx。  创建一个简单的web项目。为了直观的区分访问的哪个tomcat，在页面写上标记8081、8082。     分别部署到对应的tomcat下。如图：    配置nginx&amp;#160;&amp;#160;&amp;#160">
<meta name="twitter:image" content="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/01.png?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/Tomcat/7. Nginx + Tomcat 配置负载均衡集群/"/>





  <title>Nginx + Tomcat 配置负载均衡集群 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/Tomcat/7. Nginx + Tomcat 配置负载均衡集群/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Nginx + Tomcat 配置负载均衡集群</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:13:44+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、Hello-world"><a href="#一、Hello-world" class="headerlink" title="一、Hello world"></a>一、Hello world</h2><h3 id="前期环境准备"><a href="#前期环境准备" class="headerlink" title="前期环境准备"></a>前期环境准备</h3><ol>
<li><p>准备两个解压版tomcat，如何同时启动两个tomcat，请看我的另一篇文章《一台机器同时启动多个tomcat》。</p>
</li>
<li><p>nginx官网下载解压版nginx。</p>
</li>
<li><p>创建一个简单的web项目。为了直观的区分访问的哪个tomcat，在页面写上标记8081、8082。</p>
</li>
</ol>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/01.png?raw=true" alt=""></p>
<ol>
<li>分别部署到对应的tomcat下。如图：</li>
</ol>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/02.png?raw=true" alt=""></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/03.png?raw=true" alt=""></p>
<h3 id="配置nginx"><a href="#配置nginx" class="headerlink" title="配置nginx"></a>配置nginx</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;进入nginx-1.10.1conf路径，修改配置文件nginx.conf。</p>
<ol>
<li>配置服务器组，在http{}节点之间添加upstream配置。（注意不要写localhost，不然访问速度会很慢）</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">server 127.0.0.1:8081;   <span class="comment">#服务器地址1</span></div><div class="line">server 127.0.0.1:8082;   <span class="comment">#服务器地址2</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>修改nginx监听的端口号80，改为8080。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">server &#123;</div><div class="line">    listen       8080;</div><div class="line">    ......</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>在location{}中，利用proxy_pass配置反向代理地址；此处“<a href="http://”不能少，后面的地址要和第一步upstream定义的名称保持一致。" target="_blank" rel="external">http://”不能少，后面的地址要和第一步upstream定义的名称保持一致。</a></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">location / &#123;</div><div class="line">root   html;</div><div class="line">index  index.html index.htm;</div><div class="line">proxy_pass http://nginxDemo; <span class="comment">#配置方向代理地址</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如下图：</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/04.png?raw=true" alt=""></p>
<h3 id="启动nginx和tomcat，访问"><a href="#启动nginx和tomcat，访问" class="headerlink" title="启动nginx和tomcat，访问"></a>启动nginx和tomcat，访问</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我是Windows系统，所以直接在nginx-1.10.1目录下双击nginx.exe即可。<br>可在任务管理器中查看</p>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/05.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后在浏览器输入地址：<a href="http://localhost:8080/nginxDemo/index.jsp，每次访问就会轮流访问tomcat了（如果F5刷新不管用，建议试试鼠标指针放到地址栏，点击Enter键）。" target="_blank" rel="external">http://localhost:8080/nginxDemo/index.jsp，每次访问就会轮流访问tomcat了（如果F5刷新不管用，建议试试鼠标指针放到地址栏，点击Enter键）。</a></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/06.png?raw=true" alt=""></p>
<p><img src="https://github.com/hcldirgit/image/blob/master/Nginx%20+%20Tomcat%20%E9%85%8D%E7%BD%AE%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E9%9B%86%E7%BE%A4/07.png?raw=true" alt=""></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;到这里，一个非常简单的负载均衡就配置完成了，是不是很简单呢，O(∩_∩)O哈哈~</p>
<h2 id="二、nginx负载均衡策略"><a href="#二、nginx负载均衡策略" class="headerlink" title="二、nginx负载均衡策略"></a>二、nginx负载均衡策略</h2><h3 id="轮询（默认）"><a href="#轮询（默认）" class="headerlink" title="轮询（默认）"></a>轮询（默认）</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;每个web请求按时间顺序逐一分配到不同的后端服务器，如果后端服务器down掉，能自动剔除。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      server 127.0.0.1:8081;</div><div class="line">      server 127.0.0.1:8082;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="最少链接"><a href="#最少链接" class="headerlink" title="最少链接"></a>最少链接</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;web请求会被转发到连接数最少的服务器上。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      least_conn;</div><div class="line">      server 127.0.0.1:8081;</div><div class="line">      server 127.0.0.1:8082;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="weight-权重"><a href="#weight-权重" class="headerlink" title="weight 权重"></a>weight 权重</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定轮询几率，weight和访问比率成正比，用于后端服务器性能不均的情况，weight默认是1。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;服务器A和服务器B的访问比例为：2-1;比如有3个请求，前两个会访问A，三个访问B，其它规则和轮询一样。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      server 127.0.0.1:8081 weight=2; <span class="comment">#服务器A</span></div><div class="line">      server 127.0.0.1:8082; <span class="comment">#服务器B</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="ip-hash"><a href="#ip-hash" class="headerlink" title="ip_hash"></a>ip_hash</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;每个请求按访问ip的hash值分配，这样同一客户端连续的Web请求都会被分发到同一服务器进行处理，可以解决session的问题。当后台服务器宕机时，会自动跳转到其它服务器。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      ip_hash;</div><div class="line">      server 127.0.0.1:8081 weight=2; <span class="comment">#服务器A</span></div><div class="line">      server 127.0.0.1:8082; <span class="comment">#服务器B</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;基于weight的负载均衡和基于ip_hash的负载均衡可以组合在一起使用。</p>
<h3 id="url-hash（第三方）"><a href="#url-hash（第三方）" class="headerlink" title="url_hash（第三方）"></a>url_hash（第三方）</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;url_hash是nginx的第三方模块，nginx本身不支持，需要打补丁。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nginx按访问url的hash结果来分配请求，使每个url定向到同一个后端服务器，后端服务器为缓存服务器、文件服务器、静态服务器时比较有效。缺点是当后端服务器宕机的时候，url_hash不会自动跳转的其他缓存服务器，而是返回给用户一个503错误。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      server 127.0.0.1:8081; <span class="comment">#服务器A</span></div><div class="line">      server 127.0.0.1:8082; <span class="comment">#服务器B</span></div><div class="line">      <span class="built_in">hash</span> <span class="variable">$request_url</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="fair（第三方）"><a href="#fair（第三方）" class="headerlink" title="fair（第三方）"></a>fair（第三方）</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;按后端服务器的响应时间来分配请求，响应时间短的优先分配。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">upstream nginxDemo &#123;</div><div class="line">      server 127.0.0.1:8081; <span class="comment">#服务器A</span></div><div class="line">      server 127.0.0.1:8082; <span class="comment">#服务器B</span></div><div class="line">      fair;</div><div class="line">&#125;</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Nginx/" rel="tag"># Nginx</a>
          
            <a href="/tags/Tomcat/" rel="tag"># Tomcat</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/Tomcat/6.  tomcat配置文件server.xml详解/" rel="next" title="tomcat配置文件server.xml详解">
                <i class="fa fa-chevron-left"></i> tomcat配置文件server.xml详解
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Tomcat/9. tomcat 性能优化/" rel="prev" title="tomcat 性能优化">
                tomcat 性能优化 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、Hello-world"><span class="nav-number">1.</span> <span class="nav-text">一、Hello world</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#前期环境准备"><span class="nav-number">1.1.</span> <span class="nav-text">前期环境准备</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置nginx"><span class="nav-number">1.2.</span> <span class="nav-text">配置nginx</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动nginx和tomcat，访问"><span class="nav-number">1.3.</span> <span class="nav-text">启动nginx和tomcat，访问</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、nginx负载均衡策略"><span class="nav-number">2.</span> <span class="nav-text">二、nginx负载均衡策略</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#轮询（默认）"><span class="nav-number">2.1.</span> <span class="nav-text">轮询（默认）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最少链接"><span class="nav-number">2.2.</span> <span class="nav-text">最少链接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#weight-权重"><span class="nav-number">2.3.</span> <span class="nav-text">weight 权重</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ip-hash"><span class="nav-number">2.4.</span> <span class="nav-text">ip_hash</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#url-hash（第三方）"><span class="nav-number">2.5.</span> <span class="nav-text">url_hash（第三方）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#fair（第三方）"><span class="nav-number">2.6.</span> <span class="nav-text">fair（第三方）</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
